<template>
  <div id='subtmpl'>
        <div class="inleft div" @click="subtract">-</div>
        <div class="incenter div" v-text="count"></div>
        <div class="inright div" @click="add">+</div>
  </div>
</template>
<script>
export default {
    props:['initCount','goodsid'],
    data () {
      return {
        count:1,
        resObj:{goodsid:0,type:'add'}
      };
    },
    created(){
        this.count = this.initCount
    },
    methods:{
      add(){
        this.count++
      
        this.sendmess('add')
        
      },
      subtract(){
        this.count--
        if(this.count<1){
          this.count = 1;
          return;
        }
        this.sendmess('subtract')
      },
      sendmess(type){
          this.resObj.type = type;
          this.resObj.goodsid = this.goodsid
        this.$emit('cardataObj',this.resObj)
      }
    }
}
</script>
<style lang="css" scoped>
   #subtmpl .div{
		width: 40px;
		height: 25px;
		line-height: 25px;
		
		float: left;
		text-align: center;
        margin-right: 5px;
        border-radius: 5px;
        background: #3BB5FF;
        cursor: pointer;
	}
    #subtmpl .incenter {
        background: #fff;
        border: 1px solid #000;
    }
</style>